﻿@model IEnumerable<Commission.Models.Product>
@using MyResources = Commission.Resources.AppResource

@{
    ViewBag.Title = "Index";
}

<h3>@MyResources.LabelProductList</h3>
<br />

@if (User.IsInRole("Admin")) {
<p>
    @Html.ActionLink(@MyResources.LinkAddNewProduct, "Create")
</p>
}
    
<table class="table">
    <tr>
        <th style="width:80px">
            @MyResources.LabelProductNo
        </th>
        <th style="width:210px">
            @MyResources.LabelProductName
        </th>
        <th style="width:120px">
            @MyResources.LabelProductImage
        </th>
        <th class="text-center" style="width:100px" >
            @MyResources.LabelKHPrice
        </th>
      
        <th style="width:90px">
            @MyResources.LabelUnit
        </th>
        <th class="text-center" style="width:100px">
            @MyResources.LabelPPPoint
        </th>
        <th class="text-center">
            @MyResources.LabelNote
        </th>

        @if (User.IsInRole("Admin")) {
            <th></th>
        }
    </tr>

    @foreach (var item in Model) {
    <tr>
        
        <td>
            @Html.DisplayFor(modelItem => item.ProductNo)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ProductName)
        </td>
        <td>
            @if (item.FileId != null && item.FileId != 0) { 
                <img src="@Url.Content(item.FileUrl)" height="100" width="100" alt="Image" />
            }
        </td>
        <td class="text-right">
            @Html.DisplayFor(modelItem => item.Price)
        </td>
        
        <td class="text-center">
            @Html.DisplayFor(modelItem => item.Unit.UnitName)
        </td>
        <td class="text-right">
            @Html.DisplayFor(modelItem => item.PPPoint)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Note)
        </td>

        @if (User.IsInRole("Admin")) {
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.ProductId }) |
            @Html.ActionLink("Details", "Details", new { id=item.ProductId }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.ProductId })
        </td>
        }
    </tr>
}

</table>
